var map;

function initialize() {
    var latlng = new google.maps.LatLng(-18.8800397, -47.05878999999999);
 
    var options = {
        zoom: 5,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
 
    map = new google.maps.Map(document.getElementById("exibeMapaGeral"), options);
}
 
initialize();


var idInfoBoxAberto;
var infoBox = [];
 
function abrirInfoBox(id, marker) {
    if (typeof(idInfoBoxAberto) == 'number' && typeof(infoBox[idInfoBoxAberto]) == 'object') {
        infoBox[idInfoBoxAberto].close();
    }
 
    infoBox[id].open(map, marker);
    idInfoBoxAberto = id;
}

function carregarPontos() {
	 
	$.getJSON( "resources/js/pontos.json", function( data ) {
		
		  $.each( data, function( key, ponto ) {
			  
			  
			  var marker = new google.maps.Marker({
	                position: new google.maps.LatLng(ponto.Latitude, ponto.Longitude),
	                title: ponto.Estado,
	                map: map,
	                icon: 'resources/images/marcador.png'
	           });
			  
			  var myOptions = {
				        content: "<p style='font-size:14px'><strong>Estado: </strong>" + ponto.Estado + "<br/><strong>Investimento: </strong>R$ " + ponto.Investimento + " Milhão(ões)<br/> <strong>Total empreendimentos:</strong>"+ ponto.Empreendimentos+"</p>",
				        pixelOffset: new google.maps.Size(-150, 0)
			  };
				
			  
			  
				    infoBox[ponto.Id] = new InfoBox(myOptions);
				    infoBox[ponto.Id].marker = marker;
				 
				    infoBox[ponto.Id].listener = google.maps.event.addListener(marker, 'click', function (e) {
				        abrirInfoBox(ponto.Id, marker);
				    });
			  
				    
				    
		  });
	});	  
}


carregarPontos();
	